# 模拟Go Agent监控输出脚本

Write-Host "========================================" -ForegroundColor Cyan
Write-Host "Go Agent 监控系统启动" -ForegroundColor Green
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""

# 显示配置信息
Write-Host "[INFO] 正在加载配置文件: configs/config.yaml" -ForegroundColor Yellow
Write-Host "[INFO] Agent名称: go-agent" -ForegroundColor White
Write-Host "[INFO] 采集间隔: 30s" -ForegroundColor White
Write-Host "[INFO] 超时时间: 10s" -ForegroundColor White
Write-Host ""

# 初始化组件
Write-Host "[INFO] 正在初始化采集器..." -ForegroundColor Yellow
Write-Host "[INFO] ✓ 系统采集器已启用 (CPU, 内存, 磁盘, 网络)" -ForegroundColor Green
Write-Host "[INFO] ✓ SNMP采集器已禁用" -ForegroundColor Gray
Write-Host "[INFO] ✓ 脚本采集器已禁用" -ForegroundColor Gray
Write-Host ""

Write-Host "[INFO] 正在初始化传输器..." -ForegroundColor Yellow
Write-Host "[INFO] ✓ HTTP传输器已启用: http://all.roywise.cn:8081/api" -ForegroundColor Green
Write-Host "[INFO] ✓ gRPC传输器已禁用" -ForegroundColor Gray
Write-Host ""

# API服务初始化
Write-Host "[INFO] 正在初始化API服务..." -ForegroundColor Yellow
Write-Host "[INFO] 设备监控API: 已启用" -ForegroundColor Green
Write-Host "[INFO] 基础URL: http://all.roywise.cn:8081/api" -ForegroundColor White
Write-Host "[INFO] 心跳间隔: 30s" -ForegroundColor White
Write-Host ""

# 注册过程
Write-Host "[INFO] 开始注册agent..." -ForegroundColor Yellow
Start-Sleep -Seconds 1
Write-Host "[INFO] 获取主机信息..." -ForegroundColor White
Write-Host "[DEBUG]   主机名: DESKTOP-D6EOF0U" -ForegroundColor Cyan
Write-Host "[DEBUG]   IP地址: 198.18.0.1" -ForegroundColor Cyan  
Write-Host "[DEBUG]   操作系统: windows" -ForegroundColor Cyan
Write-Host "[DEBUG]   系统版本: windows-10" -ForegroundColor Cyan
Write-Host "[DEBUG]   Agent版本: 1.0.0" -ForegroundColor Cyan

Start-Sleep -Seconds 1
Write-Host "[INFO] 发送注册请求..." -ForegroundColor White
Start-Sleep -Seconds 1
Write-Host "[INFO] ✓ Agent注册成功!" -ForegroundColor Green
Write-Host "[DEBUG]   AgentID: 16d3631f-ed3b-45cb-a11d-fbeeb461a882" -ForegroundColor Cyan
Write-Host "[DEBUG]   Token: eyJhbGciOiJIUzUxMiJ9..." -ForegroundColor Cyan
Write-Host ""

# 启动服务
Write-Host "[INFO] 正在启动服务..." -ForegroundColor Yellow
Write-Host "[INFO] ✓ 心跳服务已启动, 间隔: 30s" -ForegroundColor Green
Write-Host "[INFO] ✓ 配置管理器已启动, 刷新间隔: 5m" -ForegroundColor Green
Write-Host "[INFO] ✓ 指标发送器已启动, 缓冲区大小: 100" -ForegroundColor Green
Write-Host ""

# 启动调度器
Write-Host "[INFO] 正在启动任务调度器..." -ForegroundColor Yellow
Write-Host "[INFO] ✓ 已添加系统指标采集任务, 间隔: 30s" -ForegroundColor Green
Write-Host "[INFO] ✓ 调度器已启动" -ForegroundColor Green
Write-Host ""

Write-Host "========================================" -ForegroundColor Cyan
Write-Host "监控系统运行中..." -ForegroundColor Green
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""

# 模拟运行循环
for ($i = 1; $i -le 3; $i++) {
    $timestamp = Get-Date -Format "HH:mm:ss"
    
    Write-Host "[$timestamp] [INFO] 开始执行监控任务..." -ForegroundColor Yellow
    
    # 模拟心跳
    Start-Sleep -Milliseconds 500
    Write-Host "[$timestamp] [DEBUG] 发送心跳: status=ONLINE" -ForegroundColor Cyan
    Write-Host "[$timestamp] [DEBUG] ✓ 心跳发送成功" -ForegroundColor Green
    
    # 模拟系统指标采集
    Start-Sleep -Milliseconds 500
    Write-Host "[$timestamp] [INFO] 采集系统指标..." -ForegroundColor White
    
    # 获取真实系统信息
    $cpu = Get-WmiObject -Class Win32_Processor | Measure-Object -Property LoadPercentage -Average | Select-Object -ExpandProperty Average
    $memory = Get-WmiObject -Class Win32_OperatingSystem
    $memUsed = [math]::Round((($memory.TotalVisibleMemorySize - $memory.FreePhysicalMemory) / $memory.TotalVisibleMemorySize) * 100, 1)
    
    Write-Host "[$timestamp] [DEBUG]   CPU使用率: $cpu%" -ForegroundColor Cyan
    Write-Host "[$timestamp] [DEBUG]   内存使用率: $memUsed%" -ForegroundColor Cyan
    Write-Host "[$timestamp] [DEBUG]   磁盘使用率: 65.3%" -ForegroundColor Cyan
    Write-Host "[$timestamp] [DEBUG]   网络入口: 125.6 KB/s" -ForegroundColor Cyan
    Write-Host "[$timestamp] [DEBUG]   网络出口: 98.2 KB/s" -ForegroundColor Cyan
    
    # 模拟数据传输
    Start-Sleep -Milliseconds 300
    Write-Host "[$timestamp] [DEBUG] ✓ 系统指标已发送到HTTP服务器" -ForegroundColor Green
    Write-Host "[$timestamp] [DEBUG] ✓ 指标数据已上报到监控平台" -ForegroundColor Green
    
    Write-Host ""
    
    if ($i -lt 3) {
        Write-Host "[INFO] 等待下一次采集 (30秒)..." -ForegroundColor Gray
        Start-Sleep -Seconds 5  # 缩短演示时间
        Write-Host ""
    }
}

Write-Host "========================================" -ForegroundColor Cyan
Write-Host "监控演示完成" -ForegroundColor Green  
Write-Host "========================================" -ForegroundColor Cyan